package com.chenyaowei.happyhub.service.GoodsService;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.chenyaowei.happyhub.mapper.GoodsMapper.GoodMapper;
import com.chenyaowei.happyhub.pojo.GoodsPojo.Good;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodServiceImpl implements GoodService {
    @Resource
    GoodMapper goodMapper;

    @Override
    public List<Good> selectGoodsByKeyword(String keyword) {
        return goodMapper.selectGoodsByKeyword(keyword);
    }

    @Override
    public List<Good> selectGoodsByType(String type) {
        return goodMapper.selectGoodsByType(type);
    }

    @Override
    public List<Good> selectGoodsByAd() {
        return goodMapper.selectGoodsByAd();
    }

    @Override
    public List<Good> selectGoods() {
        return goodMapper.selectGoods();
    }

    @Override
    public PageInfo<Good> selectGoodsByAd(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Good> allOrderPresentList = selectGoodsByAd();
        PageInfo<Good> pageInfo = new PageInfo<>(allOrderPresentList);
        return pageInfo;
    }

    public PageInfo<Good> selectGoods(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Good> allOrderPresentList = selectGoods();
        PageInfo<Good> pageInfo = new PageInfo<>(allOrderPresentList);
        return pageInfo;
    }

    @Override
    public Good selectGoodById(int id) {
        return goodMapper.selectGoodById(id);
    }

    @Override
    public List<Good> selectGoodsBySlideAd() {
        return goodMapper.selectGoodsBySlideAd();
    }

    @Override
    public void updateSalesVolume(int salesVolume, float salesPrice, String id) {
        goodMapper.updateSalesVolume(salesVolume, salesPrice, id);
    }

    @Override
    public List<Good> selectGoodsByTypeAd(String type) {
        return goodMapper.selectGoodsByTypeAd(type);
    }

    @Override
    public PageInfo<Good> selectGoodsByKeyword(int pageNum, int pageSize, String keyword) {

        PageHelper.startPage(pageNum, pageSize);
        List<Good> allOrderPresentList = selectGoodsByKeyword(keyword);
        PageInfo<Good> pageInfo = new PageInfo<>(allOrderPresentList);
        return pageInfo;
    }

    @Override
    public PageInfo<Good> selectGoodsByType(int pageNum, int pageSize, String type) {
        PageHelper.startPage(pageNum, pageSize);
        List<Good> allOrderPresentList = selectGoodsByType(type);
        PageInfo<Good> pageInfo = new PageInfo<>(allOrderPresentList);
        return pageInfo;
    }

    @Override
    public List<Good> selectAdminGood() {
        return goodMapper.selectAdminGood();
    }

    @Override
    public void updateGood(String goodId, String goodHeader, String goodMeta, String goodImage, String goodType, String goodDescription, String isAd, String isTypeAd, String isSlideAd) {
        goodMapper.updateGood(goodId,goodHeader,goodMeta,goodImage,goodType,goodDescription,isAd,isTypeAd,isSlideAd);
    }

    @Override
    public void deleteGood(String id) {
        goodMapper.deleteGood(id);
    }

    @Override
    public PageInfo<Good> searchGood(int pageNum, int pageSize, String type, String keyword, String sort, String status) {
        PageHelper.startPage(pageNum, pageSize);
        List<Good> allOrderPresentList = goodMapper.searchGood(type,keyword,sort,status);
        PageInfo<Good> pageInfo = new PageInfo<>(allOrderPresentList);
        return pageInfo;
    }


}
